package com.mixed.mixedserver.config.listeners;

import dev.langchain4j.model.chat.listener.ChatModelErrorContext;
import dev.langchain4j.model.chat.listener.ChatModelListener;
import dev.langchain4j.model.chat.listener.ChatModelRequestContext;
import dev.langchain4j.model.chat.listener.ChatModelResponseContext;
import lombok.extern.slf4j.Slf4j;

import java.util.UUID;
@Slf4j
public class TestChatListener implements ChatModelListener {

    @Override
    public void onRequest(ChatModelRequestContext requestContext) {
        UUID uuid = UUID.randomUUID();
        requestContext.attributes().put("requestId",uuid);
        log.info("开始请求requestId:{}",uuid);
        ChatModelListener.super.onRequest(requestContext);
    }

    @Override
    public void onResponse(ChatModelResponseContext responseContext) {
        System.out.println("请求完成requestId: " + responseContext.attributes().get("requestId"));
        ChatModelListener.super.onResponse(responseContext);
    }

    @Override
    public void onError(ChatModelErrorContext errorContext) {
        ChatModelListener.super.onError(errorContext);
    }
}
